<!-- 应用管理 -->
<template>
  <div class="rightCenter">
    <div class="listTop">
      <div class="listTopAddBut" @click='addClick()'>
        添加
      </div>
      <!-- <div class="listTopInpBox"> -->
      <!-- <div class="listTopInpIco">
                    <i class="icon font_family icon-sousuo"></i>
                </div> -->
      <!-- <input class="listTopInp" type="text" v-model='searchVal' oninput='searchFun' placeholder="搜索姓名/手机号 "> -->
      <!-- </div> -->
    </div>
    <ul class="listUl">
      <li class="listLi fristLI">
        <div class="listDiv listOne">
          应用名称
        </div>
        <div class="listDiv listTwo">
          AppID
        </div>
        <div class="listDiv listThree">
          AppKey
        </div>
        <div class="listDiv listFour">
          Appsecret
        </div>
        <div class="listDiv listFive">
          操作
        </div>
      </li>
      <li class="listLi dataLi" v-for="(item,index) in dataList" :class="{grayBack:index % 2 == 1}" :key='index'>
        <div class="listDiv listOne">
          {{item.name}}
        </div>
        <div class="listDiv listTwo">
          {{item.appId}}
        </div>
        <div class="listDiv listThree">
          {{item.appKey}}
        </div>
        <div class="listDiv listFour">
          {{item.secret}}
        </div>
        <div class="listDiv listFive">
          <div class="buttonBox okbut" @click='operationClick(index,1)'>
            编 辑
          </div>
          <div class="buttonBox delect" @click='operationClick(index,2)'>
            删 除
          </div>
        </div>
      </li>
    </ul>
    <div class="paging">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pageNo" :page-sizes="[10, 20, 30, 40]"
        :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper" :total="totalVal">
      </el-pagination>
    </div>
    <!-- 删除弹框 -->
    <div class="fixedBox" v-show='checkShow'>
      <div class="popupCheckBox">
        <div class="popuplistBoxTop">
          <div class="popuplistBoxTopFont">
            确认要删除该应用吗？
          </div>
          <div class="popuplistBoxTopBut" @click='delectCancelClick()'>
            <i class="icon font_family icon-chuangkouguanbi-dianji"></i>
          </div>
        </div>
        <div class="popupCheckButton">
          <div class="popupCheckPass" @click='delectOkClick()'>
            确 认
          </div>
          <div class="popupCheckFail" @click='delectCancelClick()'>
            取 消
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import { mapActions } from "vuex";
import useRequest from "../../assets/use";
export default {
  data() {
    return {
      checkShow: false, // 删除弹框
      delectIndex: 0,
      searchVal: "", //所搜
      dataList: [],
      pageNo: 1, //页码
      pageSize: 20, //每页条数
      totalVal: 0 //总数量
    };
  },
  filters: {},
  created: function() {
    let self = this;
    if (sessionStorage.getItem("TABLIST")) {
      let arr = JSON.parse(sessionStorage.getItem("TABLIST"));
      let routShow = false;
      for (let i = 0; i < arr.length; i++) {
        if (arr[i].name == "应用管理") {
          routShow = true;
        }
      }
      if (!routShow) {
        this.$router.push({
          path: "/login"
        });
        sessionStorage.clear();
        self.$message("暂无权限");
        return;
      }
    }else{
       this.$router.push({
          path: "/login"
        });
        sessionStorage.clear();
        self.$message("暂无权限");
        return;
    }
    this.searchFun();
  },
  watch: {},
  mounted() {},
  methods: {
    // 删除/编辑
    operationClick(index, val) {
      let self = this;
      if (val == 2) {
        this.delectIndex = index;
        this.checkShow = true;
      } else {
        this.$router.push({
          path: `/home/use/editCompile?appId=${self.dataList[index].appId}`
        });
      }
    },
    //确认删除
    async delectOkClick() {
      let self = this;
      let params = {
        appId: self.dataList[self.delectIndex].appId
      };
      let res = await useRequest.getappDelete(params);
      if (res.statusCode == 200) {
        self.$message("删除成功！");
        self.searchFun();
      } else {
        self.$message(res.statusMessage);
        self.dataList = [];
      }
      this.checkShow = false;
    },
    //取消删除
    delectCancelClick() {
      this.checkShow = false;
    },
    //添加
    addClick() {
      this.$router.push({
        path: "/home/use/edit"
      });
    },
    //搜索
    async searchFun() {
      let self = this;
      let params = {
        page: self.pageNo,
        size: self.pageSize
      };
      let getParams = `page=${params.page}&size=${params.size}`;
      let res = await useRequest.getappList(getParams);
      if (res.statusCode == 200) {
        if (res.data) {
          if (res.data.records) {
            self.dataList = res.data.records;
          }
          self.totalVal = res.data.total * 1;
        }
      } else {
        self.$message(res.statusMessage);
        self.dataList = [];
      }
    },
    //分页 - 每页条数
    handleSizeChange(val) {
      this.pageSize = val;
      this.searchFun();
    },
    //分页 - 页数
    handleCurrentChange(val) {
      this.pageNo = val;
      this.searchFun();
    }
  }
};
</script>
<style scoped>
.listOne {
  width: 18%;
}

.listTwo {
  width: 18%;
}

.listThree {
  width: 18%;
}

.listFour {
  width: 18%;
}

.listFive {
  width: 28%;
  display: flex;
  justify-content: center;
  align-items: center;
}

.okbut {
  background: #279de2;
  margin: 0 14px;
}

.delect {
  background: #ed4a47;
}
</style>